Skip to content

Harden RAG retrieval and answer reliability - #1289

Merged
BigSimmo merged 7 commits into
mainfrom
codex/rag-reliability-final
Jul 28, 2026
Merged

Harden RAG retrieval and answer reliability#1289
BigSimmo merged 7 commits into
mainfrom
codex/rag-reliability-final

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Harden RAG evidence binding, clinical-value verification, comparison fallback, extractive formatting, citation preservation, and fail-closed behavior across current clinical fixtures.
  • Resolve #019 admission/discharge source loss and #029 review-fallback stubs, with a zero-tolerance quality gate for recurrence.
  • Improve eval diagnostics, irrelevant-at-10 evidence, source-governance reporting, and path-specific coverage floors.
  • Add the auditable BMJ third-party attestation policy, schema/API support, migration, and pending-human-review manifest without treating BMJ content as clinically verified.
  • Reconcile the RAG backlog and evidence documents; lithium is closed, while ADHD/metabolic evidence debt, browser-matrix evidence, and human label review remain open.

RAG impact: behaviour change — canary pair output/rag-retrieval-post-final.json -> output/rag-retrieval-post-exact-head.json (36/36; document/content recall 1.0; zero per-case document/content RR regressions)

The protected retrieval change uses the expanded chunk query only for the measured clozapine blood-count action shape. Discharge and other red-section document lookups retain raw intent terms. Ranking scores, comparator order, clamps, and semantic reranking are unchanged.

Verification

  • npm run verify:cheap — PASS: 25 gates, including the full unit suite.
  • npm run test:coverage — PASS: 399 files; 4,062 passed, 2 skipped; RAG coverage 86.83% statements and 90.79% lines.
  • npm run eval:rag:offline — PASS: 36 cases, 21 suites, 560 assertions.
  • npm run check:production-readiness — PASS: 8 checks, no blockers; two isolated-worktree environment-location warnings.
  • npm run check:migration-role — PASS.
  • Final focused post-review Vitest set — PASS: 5 files, 83 tests.
  • Focused source-review lint — PASS.
  • npm run verify:pr-local — PASS on the reconciled application tree: format, zero-warning lint, typecheck, 403 test files / 4,101 passed / 2 skipped, production build/client-secret scan, and 36 offline RAG fixtures.
  • npm run eval:retrieval:quality — PASS on the reconciled application tree: 36/36, document/content recall 1.0, MRR 0.8921, content MRR 0.9406, nDCG 0.9308, irrelevant-at-10 0.0917, zero failures, and zero per-case document/content RR regressions.
  • Recorded 44-case live answer gate — 30/30 supported substantive and grounded, 14/14 unsupported correct, zero citation/numeric failures, zero review fallbacks, zero route-ceiling failures, p95 7,494 ms.
  • npm run eval:rag -- --limit 15 + npm run eval:quality -- --rag-only — superseded by the recorded full 44-case answer gate above; no weaker sample is claimed.
  • npm run verify:ui — UI verification not run: no UI, routing, styling, or browser-rendering surface changed.
  • npm run verify:release — not run: it includes additional provider-backed release work; exact-head PR-local, the protected retrieval canary, and hosted required checks are the scoped merge gates.
  • npm run check:production-readiness — result recorded above.
  • npm run check:deployment-readiness — not run: deployment startup and hosting configuration were unchanged.

Exact-head typechecking passed within npm run verify:pr-local.

Risk and rollout

  • Risk: High clinical/reliability surface. Main risks are incorrect evidence selection, misplaced numeric values, lost citations, overconfident extraction, and schema/API version skew. New fixtures and fail-closed gates cover these paths.
  • Rollback: Revert the application changes. The Supabase migration is currently unapplied, so no database rollback is required. If applied later, leave the additive schema in place and use a separately reviewed forward migration rather than dropping data.
  • Provider or production effects: Authorized live evals and read-only hosted RPC profiling were performed. No hosted migration, source attestation, or production-data write was performed. Merging to main will follow the repository's normal application/worker auto-deploy path.

Migration 20260727010000_bmj_third_party_source_attestation.sql is a separate, deliberate operator step and must not be applied automatically. Until applied, legacy owner-scoped review behavior remains available and v2-only public/attestation requests fail closed with 503 source_review_v2_unavailable.

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • Supersedes draft Harden RAG retrieval and answer reliability #1288 with a clean one-commit history so the deliberately fake token-shaped test fixture is absent from every PR commit.

  • Current reconciled head: 22b7b751247f1904b11bd53145ac18fbb0330b90.

  • BMJ sources remain clinical_validation_status=unverified; qualified human review, hosted apply, attestation, and warning-rate remeasurement remain #022.

  • Firefox/WebKit evidence and human irrelevant-at-10 disposition remain #023.

  • ADHD corpus/table accessibility and metabolic schedule evidence remain the open parts of #018.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@BigSimmo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d9b5237d-5dc2-4425-ad6d-3765fd3e203f

📥 Commits

Reviewing files that changed from the base of the PR and between b9340a3 and 22b7b75.

📒 Files selected for processing (76)
  • docs/branch-review-ledger.md
  • docs/evidence/rag-reliability-evidence-2026-07-27.md
  • docs/evidence/rag-top-local-review-manifest-2026-07-26.json
  • docs/outstanding-issues.md
  • docs/rag-behaviour/refuted-approaches.md
  • docs/rag-hybrid-findings-and-todo.md
  • docs/source-governance-refresh-worklist-2026-07-22.md
  • scripts/audit-source-governance.ts
  • scripts/build-clinical-review-queue.ts
  • scripts/eval-answer-quality.ts
  • scripts/eval-quality.ts
  • scripts/eval-retrieval.ts
  • scripts/eval-utils.ts
  • scripts/profile-retrieval-rpcs.ts
  • src/app/api/documents/[id]/reviews/route.ts
  • src/app/api/documents/bulk/route.ts
  • src/lib/answer-ranking.ts
  • src/lib/answer-verification.ts
  • src/lib/clinical-review-queue.ts
  • src/lib/clinical-search.ts
  • src/lib/clinical-value-binding.ts
  • src/lib/eval-document-matching.ts
  • src/lib/medication-entities.ts
  • src/lib/rag/rag-answer-text.ts
  • src/lib/rag/rag-cache.ts
  • src/lib/rag/rag-candidate-sources.ts
  • src/lib/rag/rag-claim-support.ts
  • src/lib/rag/rag-comparison.ts
  • src/lib/rag/rag-eval-cases.ts
  • src/lib/rag/rag-extractive-answer.ts
  • src/lib/rag/rag-extractive-artifacts.ts
  • src/lib/rag/rag-extractive-first.ts
  • src/lib/rag/rag-quote-verification.ts
  • src/lib/rag/rag-routing.ts
  • src/lib/rag/rag-source-segmentation.ts
  • src/lib/rag/rag.ts
  • src/lib/retrieval-selection.ts
  • src/lib/smart-rag-api.ts
  • src/lib/source-review.ts
  • src/lib/supabase/database.types.ts
  • supabase/drift-manifest.json
  • supabase/migrations/20260727010000_bmj_third_party_source_attestation.sql
  • supabase/schema.sql
  • tests/answer-ranking.test.ts
  • tests/answer-responsiveness-gate.test.ts
  • tests/answer-verification.test.ts
  • tests/clinical-review-queue.test.ts
  • tests/clinical-search.test.ts
  • tests/document-mutation-routes.test.ts
  • tests/eval-answer-quality.test.ts
  • tests/eval-document-matching.test.ts
  • tests/eval-quality.test.ts
  • tests/eval-retrieval.test.ts
  • tests/eval-utils.test.ts
  • tests/extractive-answer-formatting.test.ts
  • tests/medication-entities.test.ts
  • tests/profile-retrieval-rpcs.test.ts
  • tests/rag-answer-fallback.test.ts
  • tests/rag-answer-text.test.ts
  • tests/rag-claim-support.test.ts
  • tests/rag-document-lookup-chunk-query.test.ts
  • tests/rag-document-lookup-escalation-rescue.test.ts
  • tests/rag-eval-cases.test.ts
  • tests/rag-extractive-first.test.ts
  • tests/rag-extractive-procedural-artifact.test.ts
  • tests/rag-fast-path-ordering.test.ts
  • tests/rag-offline-answer.test.ts
  • tests/rag-routing.test.ts
  • tests/rag-trust.test.ts
  • tests/retrieval-selection.test.ts
  • tests/smart-rag-api.test.ts
  • tests/source-authority-tooling.test.ts
  • tests/source-review-policy.test.ts
  • tests/source-review-route.test.ts
  • tests/source-review-schema.test.ts
  • vitest.config.mts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/rag-reliability-final

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 27, 2026

Copy link
Copy Markdown

Updates to Preview Branch (codex/rag-reliability-final) ↗︎

Deployments Status Updated
Database Tue, 28 Jul 2026 00:36:40 UTC
Services Tue, 28 Jul 2026 00:36:40 UTC
APIs Tue, 28 Jul 2026 00:36:40 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Tue, 28 Jul 2026 00:36:41 UTC
Migrations Tue, 28 Jul 2026 00:36:43 UTC
Seeding Tue, 28 Jul 2026 00:36:45 UTC
Edge Functions Tue, 28 Jul 2026 00:36:46 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 28, 2026 00:12
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…-final

# Conflicts:
#	docs/outstanding-issues.md
@BigSimmo

Copy link
Copy Markdown
Owner Author

@cursoragent run bugbot review

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Bugbot review of PR #1289 — APPROVE (exact head d49af8ac; ledger commit now at 94deee52)

Findings

No high-confidence P0–P2 defects.

Severity Location Finding Disposition
No P0/P1/P2 No defect

Application src/ / supabase/ / tests/ / scripts/ are unchanged vs the prior APPROVE tip a1ca6a01. Tip delta was docs evidence + a clean merge from main. No unresolved cursor[bot] Bugbot threads on the PR.

Residual risk

Unapplied BMJ attestation migration (#022) — public/attestation reviews correctly hard-fail with 503 source_review_v2_unavailable until a qualified hosted apply.

Checks

  • Focused high-risk Vitest: 358 + 1502 passed
  • merge-tree CLEAN vs origin/main
  • Not run: live canaries / provider-backed gates (same app tree as prior recorded canary)

Ledger updated and pushed: #1289

Open in Web Open in Cursor 

@BigSimmo

Copy link
Copy Markdown
Owner Author

@claude Review this PR

@github-actions

Copy link
Copy Markdown
Contributor

Hi @BigSimmo — thanks for the @claude mention.

Open this in Claude Code on the web to continue here: https://claude.ai/code

Context: BigSimmo/Database · #1289

Automated backlink from the Claude backlink workflow. Claude Code can pick up the mention and push a scoped fix to the branch.

@claude

claude Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens high-risk RAG retrieval/answer reliability and source-governance surfaces by tightening evidence binding, improving deterministic/extractive fallbacks, strengthening eval diagnostics + quality gates, and introducing BMJ third‑party attestation support that remains explicitly unverified pending qualified human action.

Changes:

  • Strengthens retrieval selection + document lookup chunk selection to preserve intent terms and prevent wrong-subject/table-evidence promotion (notably around clozapine blood-count action shapes and lithium monitoring rows).
  • Tightens answer/eval reliability contracts (required expected-file citations, explicit handling of source-backed review stubs, richer retrieval diagnostics persisted into artifacts).
  • Adds BMJ third-party attestation policy plumbing across SQL schema/types/tests and admin-only review route behavior that fails closed when the v2 RPC/migration is unavailable.

Reviewed changes

Copilot reviewed 75 out of 76 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vitest.config.mts Adds aggregate coverage floors for core RAG/reliability modules.
tests/source-review-schema.test.ts Verifies BMJ attestation migration/schema/types invariants and fail-closed constraints.
tests/source-authority-tooling.test.ts Pins audit/backfill tooling to include source_review_events + BMJ attestation handling.
tests/smart-rag-api.test.ts Ensures extractive comparison planning is described as clinical synthesis with deterministic assembly.
tests/retrieval-selection.test.ts Adds regression cases preventing foreign-medication/foreign-table promotion and preserving subject binding.
tests/rag-offline-answer.test.ts Tightens assertion to require the correct clozapine withhold threshold signal and rejects review-stub routing.
tests/rag-fast-path-ordering.test.ts Guards stable ordering for lithium monitoring rows over higher-scored unrelated tables/foreign rows.
tests/rag-eval-cases.test.ts Adds/strengthens eval case contracts for authoritative citations and review-stub scoring behavior.
tests/rag-document-lookup-escalation-rescue.test.ts Pins the smallest-sufficient rescued evidence instead of incentivizing citation padding.
tests/rag-document-lookup-chunk-query.test.ts Covers the new chunk-query selection behavior (expanded variant only for measured clozapine action shape).
tests/rag-answer-text.test.ts Extends answer-quality heuristics around time-unit phrases (“6 hours”).
tests/medication-entities.test.ts Adds medication entity safety/catalog coverage for foreign-medication detection and binding.
tests/eval-utils.test.ts Adds required-claim + expected-citation binding validation coverage.
tests/eval-retrieval.test.ts Adds assertions for persisted per-row relevance/signal matches in golden retrieval artifacts.
tests/eval-quality.test.ts Adds CLI arg validation, safe dumping constraints, and gating behavior for unsupported-only runs.
tests/eval-document-matching.test.ts Tightens overlap rules with explicit approvals and document-identity dedupe for matching.
tests/document-mutation-routes.test.ts Prevents bulk mutation routes from writing governance status or editing reviewed identity/provenance.
tests/clinical-search.test.ts Adds foreign-threshold label handling and subject-binding regression coverage.
tests/clinical-review-queue.test.ts Extends review queue with authority classification and deterministic top-local evidence manifest.
tests/answer-responsiveness-gate.test.ts Ensures timeout fallback text doesn’t echo user typos.
tests/answer-ranking.test.ts Ensures numeric ranges stay within a single bold span.
supabase/schema.sql Adds source_review_events decision, new columns, and record_source_review_v2 with service-role-only grants.
supabase/drift-manifest.json Updates schema snapshot/hash including new columns/RPC signature.
src/lib/supabase/database.types.ts Exposes new source_review_events columns + record_source_review_v2 args.
src/lib/source-review.ts Implements BMJ attestation policy constants, eligibility checks, and event+metadata completeness verification.
src/lib/smart-rag-api.ts Adjusts intent for multi-document synthesis to reflect extractive-but-synthesis behavior.
src/lib/retrieval-selection.ts Expands FBC matching and centralizes monitoring subject matching via clinical-search helpers.
src/lib/rag/rag-source-segmentation.ts Adds bounded line reflow helpers and atomic NMHS clozapine red-range segment recovery.
src/lib/rag/rag-quote-verification.ts Hardens citation enrichment to only add deterministic support when model-selected citations are directly supported and conflict-free.
src/lib/rag/rag-extractive-artifacts.ts Detects procedural comparator artifacts (ECT flow edge/arrow glyphs) without blanket comparator rejection.
src/lib/rag/rag-eval-cases.ts Adds requiredDirectClaim contract + scoring changes to reject source-backed review stubs as “covered”.
src/lib/rag/rag-comparison.ts Adds safe comparison fallback selection that respects bounded fail-closed families.
src/lib/rag/rag-candidate-sources.ts Narrows expanded chunk-query usage to the measured clozapine blood-count action shape; otherwise preserves raw intent query.
src/lib/rag/rag-cache.ts Bumps cache dependency version to invalidate stale behavior.
src/lib/rag/rag-answer-text.ts Prevents “dose 6 hours” false positives while still flagging missing units.
src/lib/eval-document-matching.ts Adds document-identity-based dedupe + maximum matching to prevent one physical doc satisfying multiple expected slots.
src/lib/clinical-value-binding.ts Adds explicit entity↔value binding helper for clause-scoped safety checks.
src/lib/clinical-review-queue.ts Adds review class, best-rank tracking, and top-local evidence manifest builder.
src/app/api/documents/bulk/route.ts Disallows bulk governance status writes and fails closed on identity/provenance edits for reviewed sources.
src/app/api/documents/[id]/reviews/route.ts Adds BMJ attestation inputs, v2 RPC routing + fail-closed 503 when migration is unapplied, and public-doc cache invalidation.
scripts/eval-utils.ts Implements required-direct-claim semantic contract validation bound to expected-file citations.
scripts/eval-retrieval.ts Persists per-result relevance grade + matched declared signals into golden artifacts for diagnostics.
scripts/build-clinical-review-queue.ts Adds --top-local-manifest + --source-artifact support and emits deterministic manifest/report.
scripts/audit-source-governance.ts Adds service-role-only source_review_events audit to compute operational unattested debt without emitting event evidence.
docs/source-governance-refresh-worklist-2026-07-22.md Updates operator worklist with implemented BMJ policy status + manifest evidence boundaries.
docs/rag-hybrid-findings-and-todo.md Updates backlog items with landed bounded OCR repair + latency profiling evidence.
docs/rag-behaviour/refuted-approaches.md Documents additional refuted approaches and updated irrelevant@10 diagnostics posture.
docs/evidence/rag-top-local-review-manifest-2026-07-26.json Adds auditable top-local evidence manifest (pending qualified human review, no attestation applied).
docs/evidence/rag-reliability-evidence-2026-07-27.md Records local/live evidence paths and outcome metrics for the reliability work.
docs/branch-review-ledger.md Appends a review ledger entry for PR #1289 / codex/rag-reliability-final.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cursoragent and others added 2 commits July 28, 2026 00:30
Append an append-only ledger row for tip d49af8a after a Bugbot pass
found no P0–P2 on the unchanged application tree.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo

Copy link
Copy Markdown
Owner Author

Pull request overview

This PR hardens high-risk RAG retrieval/answer reliability and source-governance surfaces by tightening evidence binding, improving deterministic/extractive fallbacks, strengthening eval diagnostics + quality gates, and introducing BMJ third‑party attestation support that remains explicitly unverified pending qualified human action.

Changes:

  • Strengthens retrieval selection + document lookup chunk selection to preserve intent terms and prevent wrong-subject/table-evidence promotion (notably around clozapine blood-count action shapes and lithium monitoring rows).
  • Tightens answer/eval reliability contracts (required expected-file citations, explicit handling of source-backed review stubs, richer retrieval diagnostics persisted into artifacts).
  • Adds BMJ third-party attestation policy plumbing across SQL schema/types/tests and admin-only review route behavior that fails closed when the v2 RPC/migration is unavailable.

Reviewed changes

Copilot reviewed 75 out of 76 changed files in this pull request and generated no comments.

Show a summary per file

| File | Description |

| ---- | ----------- |

| vitest.config.mts | Adds aggregate coverage floors for core RAG/reliability modules. |

| tests/source-review-schema.test.ts | Verifies BMJ attestation migration/schema/types invariants and fail-closed constraints. |

| tests/source-authority-tooling.test.ts | Pins audit/backfill tooling to include source_review_events + BMJ attestation handling. |

| tests/smart-rag-api.test.ts | Ensures extractive comparison planning is described as clinical synthesis with deterministic assembly. |

| tests/retrieval-selection.test.ts | Adds regression cases preventing foreign-medication/foreign-table promotion and preserving subject binding. |

| tests/rag-offline-answer.test.ts | Tightens assertion to require the correct clozapine withhold threshold signal and rejects review-stub routing. |

| tests/rag-fast-path-ordering.test.ts | Guards stable ordering for lithium monitoring rows over higher-scored unrelated tables/foreign rows. |

| tests/rag-eval-cases.test.ts | Adds/strengthens eval case contracts for authoritative citations and review-stub scoring behavior. |

| tests/rag-document-lookup-escalation-rescue.test.ts | Pins the smallest-sufficient rescued evidence instead of incentivizing citation padding. |

| tests/rag-document-lookup-chunk-query.test.ts | Covers the new chunk-query selection behavior (expanded variant only for measured clozapine action shape). |

| tests/rag-answer-text.test.ts | Extends answer-quality heuristics around time-unit phrases (“6 hours”). |

| tests/medication-entities.test.ts | Adds medication entity safety/catalog coverage for foreign-medication detection and binding. |

| tests/eval-utils.test.ts | Adds required-claim + expected-citation binding validation coverage. |

| tests/eval-retrieval.test.ts | Adds assertions for persisted per-row relevance/signal matches in golden retrieval artifacts. |

| tests/eval-quality.test.ts | Adds CLI arg validation, safe dumping constraints, and gating behavior for unsupported-only runs. |

| tests/eval-document-matching.test.ts | Tightens overlap rules with explicit approvals and document-identity dedupe for matching. |

| tests/document-mutation-routes.test.ts | Prevents bulk mutation routes from writing governance status or editing reviewed identity/provenance. |

| tests/clinical-search.test.ts | Adds foreign-threshold label handling and subject-binding regression coverage. |

| tests/clinical-review-queue.test.ts | Extends review queue with authority classification and deterministic top-local evidence manifest. |

| tests/answer-responsiveness-gate.test.ts | Ensures timeout fallback text doesn’t echo user typos. |

| tests/answer-ranking.test.ts | Ensures numeric ranges stay within a single bold span. |

| supabase/schema.sql | Adds source_review_events decision, new columns, and record_source_review_v2 with service-role-only grants. |

| supabase/drift-manifest.json | Updates schema snapshot/hash including new columns/RPC signature. |

| src/lib/supabase/database.types.ts | Exposes new source_review_events columns + record_source_review_v2 args. |

| src/lib/source-review.ts | Implements BMJ attestation policy constants, eligibility checks, and event+metadata completeness verification. |

| src/lib/smart-rag-api.ts | Adjusts intent for multi-document synthesis to reflect extractive-but-synthesis behavior. |

| src/lib/retrieval-selection.ts | Expands FBC matching and centralizes monitoring subject matching via clinical-search helpers. |

| src/lib/rag/rag-source-segmentation.ts | Adds bounded line reflow helpers and atomic NMHS clozapine red-range segment recovery. |

| src/lib/rag/rag-quote-verification.ts | Hardens citation enrichment to only add deterministic support when model-selected citations are directly supported and conflict-free. |

| src/lib/rag/rag-extractive-artifacts.ts | Detects procedural comparator artifacts (ECT flow edge/arrow glyphs) without blanket comparator rejection. |

| src/lib/rag/rag-eval-cases.ts | Adds requiredDirectClaim contract + scoring changes to reject source-backed review stubs as “covered”. |

| src/lib/rag/rag-comparison.ts | Adds safe comparison fallback selection that respects bounded fail-closed families. |

| src/lib/rag/rag-candidate-sources.ts | Narrows expanded chunk-query usage to the measured clozapine blood-count action shape; otherwise preserves raw intent query. |

| src/lib/rag/rag-cache.ts | Bumps cache dependency version to invalidate stale behavior. |

| src/lib/rag/rag-answer-text.ts | Prevents “dose 6 hours” false positives while still flagging missing units. |

| src/lib/eval-document-matching.ts | Adds document-identity-based dedupe + maximum matching to prevent one physical doc satisfying multiple expected slots. |

| src/lib/clinical-value-binding.ts | Adds explicit entity↔value binding helper for clause-scoped safety checks. |

| src/lib/clinical-review-queue.ts | Adds review class, best-rank tracking, and top-local evidence manifest builder. |

| src/app/api/documents/bulk/route.ts | Disallows bulk governance status writes and fails closed on identity/provenance edits for reviewed sources. |

| src/app/api/documents/[id]/reviews/route.ts | Adds BMJ attestation inputs, v2 RPC routing + fail-closed 503 when migration is unapplied, and public-doc cache invalidation. |

| scripts/eval-utils.ts | Implements required-direct-claim semantic contract validation bound to expected-file citations. |

| scripts/eval-retrieval.ts | Persists per-result relevance grade + matched declared signals into golden artifacts for diagnostics. |

| scripts/build-clinical-review-queue.ts | Adds --top-local-manifest + --source-artifact support and emits deterministic manifest/report. |

| scripts/audit-source-governance.ts | Adds service-role-only source_review_events audit to compute operational unattested debt without emitting event evidence. |

| docs/source-governance-refresh-worklist-2026-07-22.md | Updates operator worklist with implemented BMJ policy status + manifest evidence boundaries. |

| docs/rag-hybrid-findings-and-todo.md | Updates backlog items with landed bounded OCR repair + latency profiling evidence. |

| docs/rag-behaviour/refuted-approaches.md | Documents additional refuted approaches and updated irrelevant@10 diagnostics posture. |

| docs/evidence/rag-top-local-review-manifest-2026-07-26.json | Adds auditable top-local evidence manifest (pending qualified human review, no attestation applied). |

| docs/evidence/rag-reliability-evidence-2026-07-27.md | Records local/live evidence paths and outcome metrics for the reliability work. |

| docs/branch-review-ledger.md | Appends a review ledger entry for PR #1289 / codex/rag-reliability-final. |


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cursoragent Any issues identified from copilot review?

@BigSimmo

Copy link
Copy Markdown
Owner Author

@CodeRabbit please review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@BigSimmo: I’ll review the changes, with particular attention to fail-closed behavior, evidence/citation binding, retrieval regressions, and migration/API compatibility.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@BigSimmo
BigSimmo merged commit ec04f17 into main Jul 28, 2026
19 checks passed
@BigSimmo
BigSimmo deleted the codex/rag-reliability-final branch July 28, 2026 00:50
cursor Bot pushed a commit that referenced this pull request Jul 28, 2026
Remove exact duplicate branch-review-ledger rows introduced when merging
origin/main so Static PR checks stay green.
cursor Bot pushed a commit that referenced this pull request Jul 28, 2026
Union-merge of concurrent PR #1289 rows produced exact duplicates.
Restore docs/branch-review-ledger.md from origin/main and re-append
only this PR's disposition rows.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants